var request = require('request');

const API_URL = 'https://poloniex.com/';
const CURRENCIES_URL = 'public?command=returnCurrencies';
const TICKER_URL = 'public?command=returnTicker';
const VOLUME_URL = 'public?command=return24hVolume';

function Request(params, cp) {
  request(params, function(error, response, body) {
    if (error) {
      cp(error);
    } else {
      cp(body);
    }
  });
}

const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36';
const COOKIE_VALUE = '__cfduid=d6b7b34a2b347aae2f0da828e0db4c4741515419902; _ga=GA1.2.2141906229.1515475265; _gid=GA1.2.448182387.1515475265; cf_clearance=9997fbd4eec4b4b5d09e1e2fde0437835ce03ab7-1515549887-1800; POLOSESSID=qqna5mlue16eg5uonqlj2h4lb4';

const poloniex = {

  getTicker: function(cp) {
    Request({method: 'GET',
      url: API_URL + TICKER_URL,
      headers: {
        'User-Agent': USER_AGENT,
        'Cookie': COOKIE_VALUE
      }}, cp);
  },

  getCurrencies: function(cp) {
    Request({method: 'GET', url: API_URL + CURRENCIES_URL, headers: {'User-Agent': USER_AGENT}}, cp);
  },

  get24Volume: function(cp) {
    Request({method: 'GET', url: API_URL + VOLUME_URL, headers: {'User-Agent': USER_AGENT}}, cp);
  }

};

module.exports = poloniex;
